<#import "../macro/components.ftl" as components/>
<#include "../macro/layout_default.ftl"/>

<@head>
<link rel="stylesheet" href="/misc/app/css/product_list.css"/>
<link rel="stylesheet" href="/misc/adminlte-2.3.7/plugins/daterangepicker/daterangepicker.css"/>
</@head>

<@body>
<script src="/misc/adminlte-2.3.7/plugins/daterangepicker/moment.min.js"></script>
<script src="/misc/adminlte-2.3.7/plugins/daterangepicker/daterangepicker.js"></script>
<script src="/misc/app/js/activity_list.js"></script>
<script src="/misc/jquery-fileupload-9.14.0/jquery.ui.widget.js"></script>
<script src="/misc/jquery-fileupload-9.14.0/jquery.fileupload.js"></script>
<script>var PicDomain = "${PicDomain!}"</script>
</@body>

<@layout_default>
<div class="box">
    <div class="box-header with-border">
        <span class="pull-right text-muted">共 ${activityList.resultTotal} 条记录</span>
        <input type="hidden" id="resultTotal_hidden" value="${activityList.resultTotal}" />
        <form class="form-inline" action="/activity">
        	<div class="input-group">
                <div class="input-group-addon">活动名称</div>
                <input type="text" class="form-control" style="width: 260px" name="name" value="${name!}" placeholder="活动名称"/>
            </div>
        	<div class="input-group">
                <div class="input-group-addon">渠道</div>
                <input type="text" class="form-control" style="width: 260px" name="channel" value="${channel!}" placeholder="渠道"/>
            </div>
            <div class="input-group">
                <div class="input-group-addon">状态</div>
                <select class="form-control" name="sta">
                    <option value="">全部</option>
                    <option value="0" ${(sta?exists && sta == 0)?string("selected","")}>未启用</option>
                    <option value="1" ${(sta?exists && sta == 1)?string("selected","")}>启用</option>
                    <option value="2" ${(sta?exists && sta == 2)?string("selected","")}>已停用</option>
                </select>
            </div>

            <button type="submit" class="btn btn-warning"><i class="fa fa-search"></i> 查询</button>
            <button type="button" id="search_reset" class="btn btn-warning"><i class="fa"></i> 重置</button>
            <button type="button" class="btn btn-default" name="btn_new_product"><i class="fa fa-plus"></i> 创建活动</button>
        </form>
        <form class="form-inline hide">
            <input class="form-control"/>
            <input type="email" class="form-control"/>
            <button type="submit" class="btn btn-default">Send invitation</button>
        </form>
    </div>

    <!-- /.box-header -->
    <div class="box-body">
        <table class="table table-striped table-hover">
            <tr>
                <th>ID</th>
                <th>活动名称</th>
                <th>活动时间</th>
                <th>活动区域</th>
                <th>渠道</th>
                <th>自动抽奖</th>
                <th>活动状态</th>
                <th>当前状态</th>
                <th>创建时间</th>
                <th>创建人</th>
                <th>操作</th>
            </tr>
            
            <#list activityList.result as item>
                <tr>
                    <td>${item.id?c}</td>
                    <td>${item.name}</td>
                    <td><#if item.actTimeStart?exists>${item.actTimeStart?number_to_date}至${item.actTimeEnd?number_to_date}</#if></td>
                    <td>${item.areaName!}</td>
                    <td>${item.channel}</td>
                    <td>
                    	<#if item.isAutoDraw?exists>
                    		<#if item.isAutoDraw == 1>是</#if>
                    		<#if item.isAutoDraw == 0>否</#if>
                    	</#if>
                    </td>
                    <td><#if item.sta == 0><span class="text-red">未启用</span>
                    	<#elseif item.sta == 1><span class="text-green">启用</span>
                    	<#else><span class="text-yellow">已停用</span>
                    	</#if>
                    </td>
                    <td>
                    	<#if item.sta == 0>
                    		<span class="text-red">活动未启用</span>
                    	</#if>
                    	<#if item.sta ==1>
	                    	<#if .now?long lt item.actTimeStart>活动未开始
	                    	<#elseif .now?long gt item.actTimeEnd>活动已结束
	                    	<#else><span class="text-green">活动进行中</span>
	                    	</#if>
                    	</#if>
                    	<#if item.sta==2>
                    		<span class="text-yellow">活动已停用</span>
                    	</#if>
                    </td>
                    <td>${item.cTime?number_to_datetime}</td>
                    <td>${item.cAdmin}</td>
                    <td>
                        <button type="button" class="btn btn-default btn-xs" name="btn_detail_activity" data-activity-number="${item.id?c}">查看</button>
                        <button type="button" class="btn btn-default btn-xs" name="btn_list_activity_winning" data-activity-number="${item.id?c}">兑奖记录</button>
                        
                        <#if item.sta==0>
                        	<button type="button" class="btn btn-default btn-xs" name="btn_edit_activity" data-activity-number="${item.id?c}">编辑</button>
                        	<button type="button" class="btn btn-default btn-xs" name="btn_delete_activity" data-activity-number="${item.id?c}">删除</button>
                        </#if>
                        <!--活动已启用，未进入活动时间的可编辑；已进入活动时间的不可编辑-->
                        <#if item.sta == 1>
                        	<#if .now?long lt item.actTimeEnd>
                        		<button type="button" class="btn btn-default btn-xs" name="btn_edit_activity" data-activity-number="${item.id?c}">编辑</button>
                        	</#if>
                        </#if>
                        <!--只有未开始的活动可以启用-->
                        <#if item.sta==0>
                        	<button type="button" class="btn btn-default btn-xs" name="btn_using_activity" data-activity-sta="${item.sta}" data-activity-start="${item.actTimeStart}" data-activity-end="${item.actTimeEnd}" data-activity-number="${item.id?c}">启用</button>
                        </#if>
                        <!--只有未开始和活动中的 活动可以停用-->
                        <#if item.sta == 1>
                        	<button type="button" class="btn btn-default btn-xs" name="btn_stop_activity" data-activity-sta="${item.sta}" data-activity-start="${item.actTimeStart}" data-activity-end="${item.actTimeEnd}" data-activity-number="${item.id?c}">停用</button>
                        </#if>
                        
                    	
                    </td>
                </tr>
            </#list>
            
        </table>
        <table class="table table-striped table-hover">
        	<tr>
        		<td colspan="13" style="text-align:right;background-color:white;">
        			<a href="javascript:void(0);" name="btn_export"><i class="glyphicon glyphicon-save"></i> 数据导出</a>
        		</td>
        	</tr>
        </table>
    </div>
    <!-- /.box-body -->
    <div class="box-footer text-center">
        <@components.pagination "/activity?name=${name!}&channel=${channel!}&sta=${sta!}&page=$page",activityList.page,activityList.pageTotal/>
    </div>
</div>




</@layout_default>